package org.example.testgis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.testgis.entity.PointTest;
import org.example.testgis.mapper.PointTestMapper;
import org.example.testgis.service.IPointTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PointTestServiceImpl extends ServiceImpl<PointTestMapper, PointTest> implements IPointTestService {

    @Override
    public PointTest selectById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<PointTest> selectList(PointTest point) {
        QueryWrapper<PointTest> queryWrapper = new QueryWrapper<PointTest>();
        queryWrapper.select("id,name");
        return this.getBaseMapper().selectList(queryWrapper);
    }

    @Override
    public int insertPointTest(PointTest point) {
        return baseMapper.insert(point);
    }

    @Override
    public int updatePointTest(PointTest point) {
        return baseMapper.updateById(point);
    }

    @Override
    public PointTest selectGeomById(Long id) {
        QueryWrapper<PointTest> queryWrapper = new QueryWrapper<PointTest>();
        queryWrapper.select("geom","st_asgeojson(geom) as geomJson");
        queryWrapper.eq("id", id);
        return this.getBaseMapper().selectOne(queryWrapper);
    }

    @Override
    public PointTest findGeoJsonById(Long id) {
        return baseMapper.findGeoJsonById(id, null);
    }
}
